<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>编辑活动</title>
<link href="${rc.getContextPath()}/resources/css/common.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="${rc.getContextPath()}/resources/js/jquery.js"></script>
<script type="text/javascript" src="${rc.getContextPath()}/resources/js/common.js"></script>
<script type="text/javascript" src="${rc.getContextPath()}/resources/js/jquery.validate.js"></script>
<script type="text/javascript" src="${rc.getContextPath()}/resources/js/jquery.tools.js"></script>
<script type="text/javascript" src="${rc.getContextPath()}/resources/js/messages_cn.js"></script>

<script type="text/javascript" src="${rc.getContextPath()}/resources/js/input.js"></script>
<script type="text/javascript" src="${base}/js/My97DatePicker4_8/WdatePicker.js"></script>
<script type="text/javascript" src="${base}/js/ajaxupload.js"></script>
 <!-- 引入弹出JS begin -->
<script type="text/javascript" src="${rc.getContextPath()}/js/lhgdialog/lhgdialog.min.js?self=true"></script>
<!-- 引入弹出JS end -->
 
<script>
var base = '${rc.getContextPath()}';
$().ready(function() {

	var $inputForm = $("#inputForm");
	
	// 表单验证
	$inputForm.validate({
		errorClass: "fieldError",
		rules: {
			title: {
				required:true
			}
 
		}
	});
	
	
	
	initUploadButton("titleImage");
	initUploadButton("conentImage");
	
	
});


function trim(str){ 
	  return str.replace(/^\s+|\s+$/g,''); 
} 
function save(){
 
	$('#inputForm').submit();
}
function back(){
	$.dialog.tips("返回中,请稍等...",600,"loading.gif");
	window.location.href='list.html ';
}


function initUploadButton(buttonId){
	var button = $("#"+buttonId);
	var exts = "jpg|png|gif",paths = "|";
	new AjaxUpload(button,
	{   
			action: '${base}/content/admin/uploadImage.html',   
			name: 'uploadFile',
		onSubmit : function(file, ext)
		{     
       		if ( !RegExp( "\.(?:" + exts + ")$$", "i" ).test(file) ) 
       		{
       			$.dialog.alert("只能上传以下类型：" + exts).zindex();
				return false;
			}          		         
		 	},   
		 	onComplete: function(file, response,statusText)
		 	{   
			var response = jQuery.parseJSON(response);
		 		//eval("var response = " + response + ";");
		 		if(response.status=="error")
			{
		 			$.dialog.alert("上传失败！") ;
			}
			else 
			{
				$("#"+buttonId+"Path").val(response.path);
				$.dialog.alert("上传成功！") ;
			}
		}   
	}); 
}
//预览图片
function imgShow(name) {
	if($("#"+name).val()=="") {
		$.dialog.alert("请先选择上传图片");
		return;
	}
	var path = $("#"+name).val();
	var url = '<img src="'+path+'"  />';
	$.dialog({
		lock: true,
		width:'700px',
		height:'315px',
		content: url,
		cancelVal: '关闭',
		autoSize:true,
	    cancel: function(){ //请求成功后处理函数。
	    	
		}
	});

}

function clearImage(id){
	
	$("#"+id).val("");
}

$.format = function () {
	
	 var s = arguments[0];
	
	 var reg = new RegExp("\\{" + "0" + "\\}", "gm");
	 s = s.replace(reg, arguments[1]);	 
	 return s;
}


var attachIndex = 1;
function addAttachLine() {
	var attachTpl =  $.format($("#attachTr").val(),attachIndex++);
	$('#attachTable').append(attachTpl);
}


function show()
{  
	
	var title_val = $("#title").val();
	var img_val = $("#conentImagePath").val();
	var html_val = CKEDITOR.instances.ueditTxt.getData();
	
	
   var tempForm = document.createElement("form");  

   tempForm.id="tempForm1";  

   tempForm.method="post";  

   tempForm.action="${base!}/front/eventShow.html";  

   tempForm.target="_blank";  



   var hideInput1 = document.createElement("input");  
   hideInput1.type="hidden";  
   hideInput1.name= "title"
   hideInput1.value= title_val;
   tempForm.appendChild(hideInput1);   
   
   var hideInput2 = document.createElement("input");  
   hideInput2.type="hidden";  
   hideInput2.name= "conentImg"
   hideInput2.value= img_val;
   tempForm.appendChild(hideInput2);  
   
   
   var hideInput3 = document.createElement("input");  
   hideInput3.type="hidden";  
   hideInput3.name= "html"
   hideInput3.value= encodeURI(html_val);
   tempForm.appendChild(hideInput3);  
   
 
   document.body.appendChild(tempForm);  
   tempForm.submit();
   document.body.removeChild(tempForm);

}
</script>

 
    <script>
    	var base="${rc.getContextPath()}";
    </script>
     <script type="text/javascript" src="${rc.getContextPath()}/js/ckeditor/ckeditor.js"></script>

</head>

<body>


<div class="path">
		  <a href="#"> 编辑活动</a>
	</div>
	
	<form id="inputForm" action="${base!}/event/admin/updateEvent.html" method="post">
  	<ul id="tab" class="tab">
			<li>
				<input type="button" value="基本功能" />
			</li>
			<li>
				<input type="button" value="照片上传" />
			</li>
 

		</ul>
 		<input  type="hidden"   name= "id" id="id" value="${event.id}"/>
		<!-- 基本功能begin -->
		<table class="input tabContent">
			<colgroup>
				<col  width="15%"/>
				<col  width="35%"/>
				<col  width="15%"/>
				<col  width="35%"/>
			</colgroup>
			<tr>
				<th>
					<span class="requiredField">*</span>活动名称:
				</th>
				<td   >
					 	<input  type="text"  name= "title" id="title" value="${event.title}" size="45"/>
				</td>
				 	 <th>
					 外联URL(请以http://开头):
				</th>
				<td  >
						<input  type="text"    name= "url" id="url" value="${event.url!}"  size="45"/> 
				</td>
			</tr>

 

			<tr>
				<th>
					 发布时间:
				</th>
				<td >
						<input  type="text"   name= "eventTime"  id= "eventTime" value="${event.eventTime!}" size="45" />
				</td>
				 <th>
					 活动地点:
				</th>
				<td >
						<input  type="text"   name= "eventVenue"  id= "eventVenue" value="${event.eventVenue!}" size="45" />
				</td>
			</tr>
 			<tr>
				<th>
					 活动费用说明:
				</th>
				<td colspan="3">
						<input  type="text"   name= "cost"  id="cost"  value="${event.cost!}"  size="45"/>
				</td>
 
			</tr>
 
			<tr>
				  <th>
					 活动简介:
				</th>
				<td   >
 
						<textarea  name="eventDesc" id = "eventDesc" cols="40" rows="10"   style="FONT-SIZE: 12px;" >${event.eventDesc!}</textarea>
				</td>
				<th>
					活动额外信息:
				</th>
				<td  >
						<textarea  name="moreInfo" id = "moreInfo"  cols="40" rows="10" style="FONT-SIZE: 12px;"  >${event.moreInfo!}</textarea>
				</td>
 
			</tr>
			
			<tr>
			    <th>
					 活动标题图:
				</th>
				<td  class="border_b"   valign="top"  >
					<input type ="text" id="titleImagePath" name="titleImg"  value="${event.titleImg!}"  readonly="readonly"  /><br />
					
					<input id="titleImage"  class="button"  type="button" value="上传" />
					<input id="cleartitleImage"  class="button" onclick="clearImage('titleImagePath')" type="button" value="清除" />
					<input type="button"  class="button" value="预览" onclick="imgShow('titleImagePath')"/>
					 
					<br />上传类型：*.png;*.bmp;*.jpeg;*.jpg
				</td>	
 			    <th>
					 活动内容图:
				</th>
				<td  valign="top"  >
					<input type ="text" id="conentImagePath" name="conentImg"   value="${event.conentImg!}"  readonly="readonly"  /><br />
					
					<input id="conentImage"  class="button"  type="button" value="上传" />
					<input id="clearconentImage"  class="button" onclick="clearImage('conentImagePath')" type="button" value="清除" />
					<input type="button"  class="button" value="预览" onclick="imgShow('conentImagePath')"/>
					 
					<br />上传类型：*.png;*.bmp;*.jpeg;*.jpg
				</td>
			</tr>
			 <tr>
			    <th>
					 活动状态:
				</th>
				<td  > 
						<select  name="eventStatus"  >
								<option value="1" <#if event??&&event.eventStatus ==1>selected="selected"</#if> >发布</option>
								<option value="2" <#if event??&&event.eventStatus ==2>selected="selected"</#if> >屏蔽</option>
						</select>
				</td>
 			    <th>
					 是否置顶:
				</th>
				<td  >
						<select  name="isUp"  >
								<option value="1"  <#if event??&&event.isUp ==1>selected="selected"</#if> >否</option>
								<option value="2" <#if event??&&event.isUp ==2>selected="selected"</#if> >是</option>
						</select>
				</td>
			</tr>
			 <tr>
			    <th>
					 是否头条:
				</th>
				<td  >
						<select  name="isTop"  >
								<option value="1"  <#if event??&&event.isTop ==1>selected="selected"</#if> >否</option>
								<option value="2" <#if event??&&event.isTop ==2>selected="selected"</#if> >是</option>
						</select>
				</td>
 			    <th>
					 
				</th>
				<td  >
						 <input type="hidden" name="isCases" value="1"/>
				</td>
			</tr>
			
			 <tr>
				<th>
					 活动内容:
				</th>
				<td colspan="3">
 
						 
						 <textarea rows="30" cols="50" name="content" id = "ueditTxt" >${event.content!}</textarea>
			            <script type="text/javascript">CKEDITOR.replace('content');</script>
				</td>
 
			</tr>
</table>




<!-- 基本功能begin -->
		<table class="input tabContent">
			<colgroup>
				<col  width="15%"/>
				<col  width="35%"/>
				<col  width="15%"/>
				<col  width="35%"/>
			</colgroup>
			
			<tr>
				<th>
					上传活动照片
				</th>
				<td colspan="3">
                <table border="0" id="attachTable" >
						<tbody>
							<tr>
								<td align="center"><input id="eventImgButton" name="eventImgButton" type="button" value="增加" class="button" onclick="javascript:addAttachLine();" /></td>
					 
								<td align="center">图片地址（请以http://开头）</td>
							</tr>
						</tbody>
						<#if imgList??>
							<#list imgList as img>
								<tr id="attachTr${img_index}">
									<td align="center"><input type="button" value="删除" onclick="$('#attachTr${img_index}').remove();"class="button" /></td>
									 
									<td align="center">
										<input type="text"  name="urls" <#if (img.url)??> value="${img.url}" </#if> />
									</td>
								</tr>
							</#list>
						</#if>

				 </table>
				</td>
			</tr>

			
			</table>










<table class="input">
			<colgroup>
				<col  width="15%"/>
				<col  width="35%"/>
				<col  width="15%"/>
				<col  width="35%"/>
			</colgroup>
			<tr>
				<td>

				</td>
				<td colspan="3">
					<input type="button" class="button" value="保存"  onclick="save()"/>
						<input type="button" class="button" value="预览"  onclick="show()"/>
					<input type="button" id="backButton" class="button" value="返回" onclick="javascript:back()" />
				</td>
			</tr>
		</table> 
</form>




<!-- 用于添加附件的JS代码 -->
<textarea id="attachTr" style="display:none">

<tr id="attachTr{0}">
	<td align="center"><input type="button" value="删除" onclick="$('#attachTr{0}').remove();" class="button" /></td>
 
	<td align="center">
			<input type="text" id="urls{0}" name="urls"/>
	</td>
</tr>
</textarea>



</body>
</html>